package com.adong.config;

import com.adong.pojo.User;
import com.adong.service.UserService;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;


/**
 * @author adong
 * 配置类,用来代替application.xml配置文件
 */

@Configuration //标注是配置类
// 组件扫描,value指定要扫描的类
@ComponentScan(value = "com.adong")
/*
改为注解方式为
@ComponentScan(value = "com.adong") //开启组件扫描
    includeFilters = Filter[] 指定扫描时只需要包含哪些组件
    excludeFilters = Filter[] 扫描时按照规则排除组件
案例:
    @ComponentScan(value = "com.adong", includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})}, useDefaultFilters = false)

     type:类型
       FilterType.ANNOTATION : 按照注解
       FilterType.ASSIGNABLE_TYPE : 按照给定的类型例如下面:
       FilterType.ASPECTJ : 按照ASPECTJ表达式
       FilterType.REGEX : 利用正则表达式
       FilterType.CUSTOM : 使用自定义规则,重写类实现TypeFilter接口

    @ComponentScans(
        value = {
                @ComponentScan(value = "com.adong", includeFilters = {
                        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class}),
                        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {UserService.class}),
                        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {MyTypeFilter.class})
                }, useDefaultFilters = false)
        }
)
*/
public class ApplicationConfig {

    @Bean //@Bean(value = "user") 通过value给指定id,默认使用方法名
    public User user() {
        return new User(2, "flynn");
    }


}
